package com.wei.czz.config;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

import static com.google.code.kaptcha.Constants.*;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2021-03-15 16:22:00
 * className: KaptchaConfig 谷歌图片验证码配置类
 * version: 1.0
 * description:
 */
@Configuration
public class KaptchaConfig {

    @Bean
    public DefaultKaptcha producer() {
        Properties properties = new Properties();
        // 是否打开边框[0-yes（打开）1-no（关闭）],默认值：0-yes
        properties.put(KAPTCHA_BORDER, "no");
        // 验证码图片宽度
        properties.put(KAPTCHA_IMAGE_WIDTH, "170");
        // 验证码图片高度
        properties.put(KAPTCHA_IMAGE_HEIGHT, "50");
        // 验证码文字颜色
        properties.put(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "black");
        // 验证码个数
        properties.put(KAPTCHA_TEXTPRODUCER_CHAR_SPACE, "5");
        // 验证码字体
        properties.put(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial,Courier,cmr10,宋体,楷体,微软雅黑");
        Config config = new Config(properties);
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}
